################################################################################
# Replication script for figure 3
# The populist radical right as memory entrepreneur? The prominence, sentiment, and interpretations of history in the German parliament
# British Journal of Political Science
################################################################################
rm(list = ls())

setwd("C:/Users/fkrawatzek/Dropbox/AfD/Writings/2022 National analysis/BJPS submission/BJPS_revision/dataverse")

pacman::p_load(openxlsx, ggplot2)

stand_theme <- theme(plot.title=element_text(hjust=0.5, size=20),
                     axis.title.y=element_text(vjust=1,size=16),
                     axis.text.y=element_text(size=16),
                     axis.text.x=element_text(size=16),
                     plot.subtitle=element_text(size=12),
                     plot.caption = element_text(),
                     legend.text=element_text(size=16),
                     legend.key.size=unit(3, 'lines'),
                     legend.title=element_blank())

scale4_blackwhite <- c("#000000","#3a3a3a","#838383", "#c9c9c9")

SentimentDF <- read.xlsx("./Data Figure 3.xlsx", sheet = 1)

ggplot(SentimentDF, aes(x = Party, y = deMeaned, fill = `Root.Terms`)) +
  geom_bar(stat = "identity", position = position_dodge(), alpha= 0.9) +
  labs(title = "De-Meaned Sentiment Score - National Parliaments",
       subtitle = "Based on Rauh's Augmented Dictionary",
       caption = "Values represent deviations in the parties' sentiment respective to the mean sentiment in each Root Term group.",
       x ="",
       y = "De-Meaned Sentiment",
       size = 16) +
  scale_fill_brewer(palette = "Set2") +
  geom_text(data=SentimentDF, aes(label=format(round(deMeaned, 4), nsmall = 2)),
            position=position_dodge(0.9), vjust = ifelse(SentimentDF$deMeaned > 0, -0.5, 1.5)) +
  geom_hline(yintercept = 0) +
  stand_theme
filename <- "./Figur3 Mean sentiment score-colour.png"
ggsave(file = filename, width = 12, height = 8, dpi=600)
